home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-28 | 1.7 KB | 66 lines | [TEXT/CWIE] |
- // ConstArrayLoop.h
-
- #ifndef ConstArrayLoop_h
- #define ConstArrayLoop_h
-
- #ifndef ConstArrayOf_h
- #include "ConstArrayOf.h"
- #endif
-
- template < class Element >
- class ConstArrayLoop
- {
- private:
- const Element *position;
- const Element *const stop;
- const Element *const elementZero;
-
- public:
- inline ConstArrayLoop( ConstArrayOf<Element> array );
- inline ConstArrayLoop( ConstArrayOf<Element> array, uint32 begin, uint32 end );
- inline ConstArrayLoop( ConstArrayOf<Element> array, Range<uint32> range );
-
- bool Finished() const { return position >= stop; }
- bool Unfinished() const { return position < stop; }
-
- const Element *operator++() { return ++position; }
- const Element *operator++(int) { return position++; }
-
- const Element& operator*() const { return *position; }
- const Element *operator->() const { return position; }
- };
-
- template < class Element >
- ConstArrayLoop<Element>::ConstArrayLoop( ConstArrayOf<Element> array )
- : position( array.Start() ),
- elementZero( array.Start() ),
- stop( array.End() )
- {
- Assert( !array.Null() );
- }
-
- template < class Element >
- ConstArrayLoop<Element>::ConstArrayLoop( ConstArrayOf<Element> array,
- uint32 begin,
- uint32 end )
- : position( array.Start() + begin ),
- elementZero( array.Start() ),
- stop( array.Start() + end )
- {
- Assert( begin <= end );
- Assert( end <= array.Length() );
- }
-
- template < class Element >
- ConstArrayLoop<Element>::ConstArrayLoop( ConstArrayOf<Element> array,
- Range<uint32> range )
- : position( array.Start() + range.Start() ),
- elementZero( array.Start() ),
- stop( array.Start() + range.End() )
- {
- Assert( range.Start() <= range.End() );
- Assert( range.End() <= array.Length() );
- }
-
- #endif
-